package com.swufe.scoresforapp.Yonghu;

import android.media.Image;
import android.util.Log;

import com.swufe.scoresforapp.Computeclass;
import com.swufe.scoresforapp.bean.SchoolBean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.xml.transform.Result;

public class Dataimport {
    /*
    启动数据库需要用到的一些信息设置
     */
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://192.168.1.5/xinxi?seUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&verifyServerCertificate=false&useSSL=false";
    // 数据库的用户名与密码，需要根据自己的设置 此处的ip为本机wlanIP(10.64.172.2) 当连接有线时，需要用另一种
    static final String USER = "root";
    static final String PASS = "199802";
    static Connection conn = null;
    static Statement stmt = null;
    private Connection con = null;

    private ArrayList<SchoolBean> mSchoolBeans;//获取学校信息

    public Connection getCon() throws ClassNotFoundException, SQLException {

        // 注册 JDBC 驱动
        Class.forName("com.mysql.jdbc.Driver");
        // 打开链接
        //连接数据库..."
        con = DriverManager.getConnection(DB_URL,USER,PASS);
        return con;
    }
    public void closeCon() throws SQLException {
        con.close();
    }
    public boolean open(){
        try{
            // 注册 JDBC 驱动
            Class.forName("com.mysql.jdbc.Driver");
            // 打开链接
            //连接数据库..."
            conn = DriverManager.getConnection(DB_URL,USER,PASS);
            // 执行查询  实例化Statement对象...
            stmt = conn.createStatement();
        }catch(SQLException se){
            // 处理 JDBC 错误
            se.printStackTrace();
            return false;
        }catch(Exception e){
            // 处理 Class.forName 错误
            e.printStackTrace();
            return false;
        }
        return true;
    }
    //完成操作时关闭链接
    public void close(){
        try {
            stmt.close();
            conn.close();
        }
        catch(Exception e) {}
    }

    /*******************************************************/
    //根据用户名称查询获得用户信息(对用户信息表的操作)
    //获取密码
    public String getPassword(String name){
        open();
        String pass = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                pass=rs.getString("密码");
            }
        } catch(SQLException e){
            Log.i("error",""+e);
        }
        close();
        return pass;
    }
    //获取生源地
    public String getArea(String name){
        open();
        String area = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        Log.i("SQL",sql);
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                area =rs.getString("生源地");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return area;
    }
    //获取分数
    public String getScore(String name) {
        open();
        String score = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                score =rs.getString("分数");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return score;
    }
    //获取考试科类
    public String getType(String name){
        open();
        String type = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                type =rs.getString("学科类别");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return type;
    }
    //获取考试年份（计算接口）
    public String getYear(String name){
        open();
        String year = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        Log.i("Sql",sql);
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                year =rs.getString("年份");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return year;
    }
    //获取排名
    public String getOrder(String name){
        open();
        String order = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                order =rs.getString("排名");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return order;
    }
    public String getTop(String name){
        open();
        String top = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        //Log.i("Sql",sql);
        try{
            ResultSet rs = stmt.executeQuery(sql);
            if(rs==null){
                return null;
            }
            while(rs.next()){
                top =rs.getString("上限排名");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return top;
    }
    public String getLow(String name){
        open();
        String sex = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        //Log.i("Sql",sql);
        try{
            ResultSet rs = stmt.executeQuery(sql);
            if(rs==null)return null;
            while(rs.next()){
                sex =rs.getString("下限排名");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return sex;
    }
    //获取性别
    public String getSex(String name){
        open();
        String sex = new String();
        String sql = "select * from 用户信息表 where 用户账号='"+name+"'";
        Log.i("Sql",sql);
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                sex =rs.getString("性别");
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return sex;
    }
    /*******************************************************/

    //一份一档表的操作
    /*******************************************************/
    //根据分数查询排名
    public String getOrder(String year, String area, String type, String score){
        String order = new String();
        String max = getMax(year,area,type);
        String sql = "select * from "+year+area+type+" where 分数 =\""+score+"\"";
        open();
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                order = rs.getString("累计人数");
            }
        }catch(SQLException e){}
        close();
        if(order==null||order.equals("")) order = "输入分数有误";
        return order;
    }
    //获取最大分数
    public String getMax(String year, String area, String type){
        String Max = new String();
        String sql = "select * from "+year+area+type+" ordered by 分数 ";
        open();
        try{
            ResultSet rs = stmt.executeQuery(sql);
            int count = 0;
            while(count <1){
                Max = rs.getString("分数");
                count++;
            }
        }catch(SQLException e){}
        close();
        return Max;
    }


    //对用户收藏学校信息的获取
    /*******************************************************/
    //获取收藏学校(完成)
    public ArrayList<SchoolBean> getShoucangXuexiao(String Yonghu) {
        open();
        ResultSet rs,rs2;
        String sql = "select * from 收藏学校 where 用户账号='"+Yonghu+"'";
        String school = new String();
        String rate = new String();
        String site,phone,location,type,majornum, belong,shuoshi;
        String boshi,if985,if211,photosource;
        try{
            Statement stmt2 ;
            rs = stmt.executeQuery(sql);
            stmt2= conn.createStatement();
            mSchoolBeans = new ArrayList<>();
            try{
                while(rs.next()) {
                    rate = rs.getString("录取概率");
                    checknull(rate);
                    school = rs.getString("学校名称");
                    school.trim();
                    rs2 = stmt2.executeQuery("select * from 学校信息表 where 学校名称 = \"" + school + "\"");
                    while (rs2.next()) {
                        site = rs2.getString("官网网址");
                        phone = rs2.getString("招生电话");
                        location = rs2.getString("所在地");
                        type = rs2.getString("学校类别");
                        majornum = rs2.getString("重点学科数");
                        belong = rs2.getString("所属部门");
                        shuoshi = rs2.getString("硕士点数");
                        boshi = rs2.getString("博士点数");
                        if985 = rs2.getString("是否985");
                        if211 = rs2.getString("是否211");
                        photosource = rs2.getString("图片");
                        site = checknull(site);
                        phone = checknull(phone);
                        location = checknull(location);
                        type = checknull(type);
                        majornum = checknull(majornum);
                        belong = checknull(belong);
                        shuoshi = checknull(shuoshi);
                        checknull(site);
                        boshi = checknull(boshi);
                        if985 = checknull(if985);
                        if211 = checknull(if211);
                        photosource = checknull(photosource);
                        mSchoolBeans.add(new SchoolBean(Yonghu,rate,school, site, phone,
                                location, type, majornum, belong, shuoshi, boshi,
                                if985, if211, photosource));

                    }
                }
            } catch(Exception e){
                    Log.e("error",""+e);
            }

                   // m = new SchoolBean()
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return mSchoolBeans;
    }
    //获取收藏学校名称
    public ArrayList<String> getShoucang(String Yonghu) {
        open();
        ResultSet rs;
        ArrayList<String> School = new ArrayList<>();
        String sql = "select * from 收藏学校 where 用户账号='"+Yonghu+"'";
        String school = new String();
        try{
            rs = stmt.executeQuery(sql);
            mSchoolBeans = new ArrayList<>();
            try{
                while(rs.next()) {
                    school = rs.getString("学校名称");
                    school.trim();
                    School.add(school);
                }
            } catch(Exception e){
                Log.e("error",""+e);
            }

            // m = new SchoolBean()
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return School;
    }


    //对用户收藏专业信息的获取
    /*******************************************************/
    //获取收藏专业（完成）
    public ArrayList<SchoolBean> getShoucangMajor(String Yonghu) {
        String area = getArea(Yonghu);
        String studenttype = getType(Yonghu);
        open();
        ResultSet rs,rs2;
        String school = new String();
        String major = new String();
        String rate = new String();
        String site = new String();
        String phone = new String();
        String location = new String();
        String type = new String();
        String majornum = new String();
        String belong = new String();
        String shuoshi = new String();
        String boshi= new String();
        String if985= new String();
        String if211= new String();
        String photosource= new String();
        String year;
        Yonghu.trim();
        String sql = "select * from 收藏专业 where 用户账号='"+Yonghu+"'";
        String low = new String();
        String ave = new String();
        String name = new String();
        try{
            rs = stmt.executeQuery(sql);
            Statement stmt2 ;
            stmt2= conn.createStatement();
            mSchoolBeans = new ArrayList<>();
            while(rs.next()) {
                //String school,String rate,String major,String low,String average,String top
                school = rs.getString("学校名称");
                major = rs.getString("专业名称");
                major = major.trim();
                school = school.trim();
                sql = "select * from 学校信息表 where 学校名称 = \"" + school + "\"";
                Log.i("TESTSQL", sql);
                if(!name.equals(school)){
                rs2 = stmt2.executeQuery(sql);
                while (rs2.next()) {
                    site = rs2.getString("官网网址");
                    Log.i("InfoCheck", site);
                    phone = rs2.getString("招生电话");
                    location = rs2.getString("所在地");
                    type = rs2.getString("学校类别");
                    majornum = rs2.getString("重点学科数");
                    belong = rs2.getString("所属部门");
                    shuoshi = rs2.getString("硕士点数");
                    boshi = rs2.getString("博士点数");
                    if985 = rs2.getString("是否985");
                    if211 = rs2.getString("是否211");
                    photosource = rs2.getString("图片");
                    name = school;
                }

                    /*String Rate,
                    String school,String site,
                            String phone,String location,
                            String type,String majornum,
                            String belong,String shuoshi,
                            String boshi,String if985,
                            String if211,String photosource*/
                }mSchoolBeans.add(new SchoolBean(Yonghu,major, studenttype, area,
                        school, site, phone,
                        location, type, majornum, belong, shuoshi, boshi,
                        if985, if211, photosource));
            }
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return mSchoolBeans;
    }
    //获取收藏专业名称
    public ArrayList<String> getMShoucang(String Yonghu) {
        open();
        ResultSet rs;
        ArrayList<String> School = new ArrayList<>();
        String sql = "select * from 收藏专业 where 用户账号='"+Yonghu+"'";
        String school = new String();
        try{
            rs = stmt.executeQuery(sql);
            mSchoolBeans = new ArrayList<>();
            try{
                while(rs.next()) {
                    school = rs.getString("专业名称");
                    school.trim();
                    School.add(school);
                }
            } catch(Exception e){
                Log.e("error",""+e);
            }

            // m = new SchoolBean()
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return School;
    }

    //对学校信息进行检索
    /*******************************************************/
    //获取图片url,无需开启和关闭数据库连接
    public String getPhotoUrl(String school){
        String url = new String();
        ResultSet rs = null;
        school.trim();
        String sql = "select * from 学校信息表 where 学校名称='"+school+"'";
        Log.i("sqlsus","");
        try{
            rs = stmt.executeQuery(sql);
            try{
                while(rs.next()) {
                    url = rs.getString("图片");
                }
            }catch (SQLException e){}
        } catch(SQLException e){
            Log.e("error",""+e);
        }
        return url;
    }
    //获取单条学校信息,无需开启和关闭数据库连接
    public SchoolBean getSchool(String school){
        open();
        if(school==null||school.equals("")){
            return new SchoolBean("无","","",
                    "","","","","","",
                    "","","");
        }
        String name = new String();
        String site,phone,location,type,majornum, belong,shuoshi;
        String boshi,if985,if211,photosource,year,studentfrom;
        //String
        SchoolBean schoolBeans = null;
        ResultSet rs = null;
        String sql = "select * from 学校信息表 where 学校名称 =\""+school+"\"";
        try{
            rs = stmt.executeQuery(sql);
            while(rs.next()){
                name = rs.getString("学校名称");
                site = rs.getString("官网网址");
                phone = rs.getString("招生电话");
                location  = rs.getString("所在地");
                type = rs.getString("学校类别");
                majornum = rs.getString("重点学科数");
                belong = rs.getString("所属部门");
                shuoshi = rs.getString("硕士点数");
                boshi = rs.getString("博士点数");
                if985 = rs.getString("是否985");
                if211 = rs.getString("是否211");
                photosource = rs.getString("图片");
                name = checknull(name);
                site = checknull(site);
                phone =checknull(phone);
                location = checknull(location);
                type = checknull(type);
                majornum = checknull(majornum);
                belong = checknull(belong);
                shuoshi = checknull(shuoshi);
                checknull(site);
                boshi = checknull(boshi);
                if985 = checknull(if985);
                if211 = checknull(if211);
                photosource = checknull(photosource);
                schoolBeans = new SchoolBean(name,site,phone,
                        location,type,majornum,belong,shuoshi,boshi,
                        if985,if211,photosource);
            }



        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return schoolBeans;
    }
    //获取学校全部信息
    public ArrayList<SchoolBean> getCollege(String school){
        String name = new String();
        String site,phone,location,type,majornum, belong,shuoshi;
        String boshi,if985,if211,photosource,year,studentfrom;
        String studenttype,low,average;
       //String
        open();
        ResultSet rs = null;
        String []sort;
        String sql = "select * from 学校信息表";
        Log.i("sqlsus","");
        try{
            rs = stmt.executeQuery(sql);
            mSchoolBeans = new ArrayList<>();
            if(school==null||school.equals("")){
                int count = 0;
                while(count<10&&rs.next()){
                    name = rs.getString("学校名称");
                    site = rs.getString("官网网址");
                    phone = rs.getString("招生电话");
                    location  = rs.getString("所在地");
                    type = rs.getString("学校类别");
                    majornum = rs.getString("重点学科数");
                    belong = rs.getString("所属部门");
                    shuoshi = rs.getString("硕士点数");
                    boshi = rs.getString("博士点数");
                    if985 = rs.getString("是否985");
                    if211 = rs.getString("是否211");
                    photosource = rs.getString("图片");
                    mSchoolBeans.add(new SchoolBean(name,site,phone,
                            location,type,majornum,belong,shuoshi,boshi,
                            if985,if211,photosource));
                    count++;
                }
            }else{
                while(rs.next()) {
                    name = rs.getString("学校名称");
                    sort = school.split("\\+s");
                    if(compareStr(sort,name)){
                        name = rs.getString("学校名称");
                        site = rs.getString("官网网址");
                        phone = rs.getString("招生电话");
                        location  = rs.getString("所在地");
                        type = rs.getString("学校类别");
                        majornum = rs.getString("重点学科数");
                        belong = rs.getString("所属部门");
                        shuoshi = rs.getString("硕士点数");
                        boshi = rs.getString("博士点数");
                        if985 = rs.getString("是否985");
                        if211 = rs.getString("是否211");
                        photosource = rs.getString("图片");
                        mSchoolBeans.add(new SchoolBean(name,site,phone,
                                location,type,majornum,belong,shuoshi,boshi,
                                if985,if211,photosource));
                    }
                }
            }

        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return mSchoolBeans;
    }

    //获取学校录取最低分
    public String getSchGuessLowOrder(String school,String studentsource,String studenttype){
        String low = new String();
        school.trim();
        studentsource.trim();
        studenttype.trim();
        String sql = "Select * from 预测学校排名 where 学校名称 = \""+school+
                "\" and 生源地 = \""+studentsource+"\" and 文理 = \""+studenttype+"\"";
        open();
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                low = rs.getString("预测学校最低排名");
            }
        }catch(SQLException e){}
        close();
        if(low==null||low.equals("")) low = "无当年数据";
        return low;
    }

    //对专业信息表操作分数
    /*******************************************************/
    public ArrayList<SchoolBean> getMajor(String majorkey,String yonghu){
        String name = new String();
        String site =new String();
        String phone=new String();
        String location=new String();
        String type=new String();
        String majornum=new String();
        String belong=new String();
        String shuoshi=new String();
        String boshi=new String();
        String if985=new String();
        String if211=new String();
        String photosource=new String();
        String year=new String();
        String studentfrom=getArea(yonghu);//根据用户信息筛选显示学校专业
        String major=new String();
        String studenttype= new String();//getType(yonghu);
        String low=new String();
        String average=new String();
        //String
        open();
        ResultSet rs,rs1;
        String []sort;
        List<String> check = new ArrayList<>();
        String temp = new String();
        String sql = "select * from 专业排名 where 生源地 = \""+studentfrom+"\" ";//and `文/理`= \""+studenttype+"\"";
        //Log.i("sqlsus","");
        mSchoolBeans = new ArrayList<>();
        try{
            Statement stmt2 = conn.createStatement();
            rs = stmt.executeQuery(sql);
            if(majorkey==null||majorkey.equals("")){
                int count = 0;
                while(count<10&&rs.next()) {
                    major = rs.getString("专业");
                    name = rs.getString("学校名称");
                    if(!(check.contains(major)&&temp.equals(name.trim()))){
                        check.add(major);
                        studentfrom = rs.getString("生源地");
                        studenttype = rs.getString(5);//文理科

                        String sql2 = "Select * from 学校信息表 where 学校名称 = \"" + name.trim() + "\"";
                        if(!temp.equals(name.trim())) {
                            rs1 = stmt2.executeQuery("Select * from 学校信息表 where 学校名称 = \"" + name.trim() + "\"");
                            //Log.i("checkSql", sql2);
                            while (rs1.next()) {
                                site = rs1.getString("官网网址");
                                phone = rs1.getString("招生电话");
                                location = rs1.getString("所在地");
                                type = rs1.getString("学校类别");
                                majornum = rs1.getString("重点学科数");
                                belong = rs1.getString("所属部门");
                                shuoshi = rs1.getString("硕士点数");
                                boshi = rs1.getString("博士点数");
                                if985 = rs1.getString("是否985");
                                if211 = rs1.getString("是否211");
                                photosource = rs1.getString("图片");
                             }
                            temp = name.trim();
                        }
                        mSchoolBeans.add(new SchoolBean(major, studenttype, studentfrom,
                                name, site, phone,
                                location, type, majornum, belong, shuoshi, boshi,
                                if985, if211, photosource));
                        count++;
                    }

                }
            }else{
                while(rs.next()) {
                    name = rs.getString("专业");
                    sort = majorkey.split("\\+s");
                    if(compareMajor(sort,name)){
                        major = rs.getString("专业");
                        studentfrom = rs.getString("生源地");
                        if(!(check.contains(major)&&temp.equals(name.trim()))){
                            studenttype = rs.getString(5);//文理科
                             name = rs.getString("学校名称");
                            String sql2 = "Select * from 学校信息表 where 学校名称 = \""+name.trim()+"\"";
                        //rs1 = stmt2.executeQuery("Select * from 学校信息表 where 学校名称 = \""+name.trim()+"\"");
                        //Log.i("checkSql", sql2);
                            if(!temp.equals(name.trim())) {
                                 rs1 = stmt2.executeQuery("Select * from 学校信息表 where 学校名称 = \"" + name.trim() + "\"");
                                Log.i("checkSql", sql2);
                                 while (rs1.next()) {
                                    site = rs1.getString("官网网址");
                                    phone = rs1.getString("招生电话");
                                    location = rs1.getString("所在地");
                                    type = rs1.getString("学校类别");
                                    majornum = rs1.getString("重点学科数");
                                    belong = rs1.getString("所属部门");
                                     shuoshi = rs1.getString("硕士点数");
                                    boshi = rs1.getString("博士点数");
                                    if985 = rs1.getString("是否985");
                                    if211 = rs1.getString("是否211");
                                    photosource = rs1.getString("图片");
                                }
                            temp = name.trim();
                                 check.add(major);
                        }
                        mSchoolBeans.add(new SchoolBean(major,studenttype,studentfrom,
                                name,site,phone,
                                location,type,majornum,belong,shuoshi,boshi,
                                if985,if211,photosource));
                        }
                    }
                }
            }

        } catch(SQLException e){
            Log.e("error",""+e);
        }
        close();
        return mSchoolBeans;
    }
    //获取单条数据信息(协助获取收藏信息)

    //获取专业最低分 输入为学校 年份 专业 生源地 考生类型
    public String getLow(String school,String year,String major,String studentsource,String studenttype){
        String low = new String();
        school.trim();
        year.trim();
        major.trim();
        studentsource.trim();
        studenttype.trim();
        String sql = "Select * from 专业排名 where 学校名称 = \""+school+"\" and 专业 = \""+major+
                "\" and 年份 = \""+ year+"\" and 生源地 = \""+studentsource+"\" and 文理 = \""+studenttype+"\"";
        Log.i("TestSql",sql);
        open();
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                low = rs.getString("专业最低分");
            }
        }catch(SQLException e){}
        close();
        if(low==null||low.equals("")) low = "无当年数据";
        return low;
    }
    //获取专业最低排名 输入为学校 年份 专业 生源地 考生类型
    public String getLowOrder(String school,String year,String major,String studentsource,String studenttype){
        String low = new String();
        school.trim();
        year.trim();
        major.trim();
        studentsource.trim();
        studenttype.trim();
        String sql = "Select * from 专业排名 where 学校名称 = \""+school+"\" and 专业 = \""+major+
                "\" and 年份 = \""+ year+"\" and 生源地 = \""+studentsource+"\" and 文理 = \""+studenttype+"\"";
        Log.i("Sql",sql);
        open();
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                low = rs.getString("专业最低排名");
            }
        }catch(SQLException e){}
        close();
        if(low==null||low.equals("")) low = "无当年数据";
        return low;
    }
    //获取专业预测最低排名 输入为学校 年份 专业 生源地 考生类型
    public String getGuessLowOrder(String school,String major,String studentsource,String studenttype){
        String low = new String();
        school.trim();
        major.trim();
        studentsource.trim();
        studenttype.trim();
        String sql = "Select * from 预测专业排名 where 学校名称 = \""+school+"\" and 专业名称 = \""+major+
                "\" and 省份 = \""+studentsource+"\" and 文理 = \""+studenttype+"\"";
        //Log.i("SQL",sql);
        open();
        try{
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                low = rs.getString("预测专业最低排名");
            }
        }catch(SQLException e){}
        close();
        if(low==null||low.equals("")) low = "无当年数据";
        return low;
    }
    //对用户收藏对比表操作
    /*******************************************************/
    public ArrayList<SchoolBean> getCollectList(String yonghu){
        mSchoolBeans = new ArrayList<>();
        open();
        ResultSet rs;
        String schoola,schoolb,schoolc,schoold;
        String sql = "select * from 收藏对比 where 用户账号 =\""+yonghu+"\"";
        Log.i("Sqltest",sql);
        try{
            rs = stmt.executeQuery(sql);
            while(rs.next()){
                schoola = rs.getString("学校1");
                checknull(schoola);
                schoolb = rs.getString("学校2");
                checknull(schoolb);
                schoolc = rs.getString("学校3");
                checknull(schoolc);
                schoold = rs.getString("学校4");
                checknull(schoold);
                mSchoolBeans.add(new SchoolBean(yonghu,schoola,schoolb,schoolc,schoold));
            }
        }catch (Exception e){}
        close();
        return mSchoolBeans;
    }
    /*******************************************************/

    //对最低录取排名的预测
    /*******************************************************/
    //获取最低录取排名

    //处理空数据
    public String checknull(String s){
        if(s == null||s.equals("null"))s ="";
        return s;
    }
    //字符串检验算法 当source中包含sort中的字段就返回true
    private boolean compareStr(String[] sort,String source){
        int i = 0;
        int length = sort.length;
        double test;
        for(;i<length;i++){
            test= Computeclass.SimilarDegree(sort[i],source);
            if(test>0.250)return true;
        }
        return false;
    }
    private boolean compareMajor(String[] sort,String source){
        int i = 0;
        int length = sort.length;
        double test;
        for(;i<length;i++){
            test= Computeclass.SimilarDegree(sort[i],source);
            if(test>0.450)return true;
        }
        return false;
    }
}
